package com.hpeng.gl.service.impl;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

import com.hpeng.gl.dao.DepartmentDao;
import com.hpeng.gl.service.DepartmentService;
import com.hpeng.sys.model.Department;

@Component("departmentService")
public class DepartmentServiceImpl implements DepartmentService {

	@Resource
	private DepartmentDao departmentDao;
	
	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public Department addDepartment(Department department) {
		return departmentDao.save(department);
	}

	public void delDepartment(Department department) {
		departmentDao.remove(department.getDepid());
	}
	//判断部门是否可用  可用的情况下  才返回值
	public List<Department> findDepartment() {	
		List<Department> list = new ArrayList<Department>();
		List<Department> lists = departmentDao.getAll();
		for(int i=0;i<lists.size();i++){
			if(lists.get(i).getDepstatus().equals("A")){
				list.add(lists.get(i));
			}
		}
		return list;
	}

	public Department findDepartmentById(String depid) {
		return departmentDao.get(depid);
	}

	public void updateDepartment(Department department) {
		departmentDao.update(department);
	}

}

